package com.youlai.boot.system.service.impl;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.boot.system.mapper.LpsOrderFsMapper;
import com.youlai.boot.system.service.LpsOrderFsService;
import com.youlai.boot.system.model.entity.LpsOrderFs;
import com.youlai.boot.system.model.form.LpsOrderFsForm;
import com.youlai.boot.system.model.query.LpsOrderFsQuery;
import com.youlai.boot.system.model.vo.LpsOrderFsVO;
import com.youlai.boot.system.converter.LpsOrderFsConverter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;

/**
 * 莱普森扶手服务实现类
 *
 * @author youlaitech
 * @since 2025-08-18 10:16
 */
@Service
@RequiredArgsConstructor
public class LpsOrderFsServiceImpl extends ServiceImpl<LpsOrderFsMapper, LpsOrderFs> implements LpsOrderFsService {

    private final LpsOrderFsConverter lpsOrderFsConverter;

    /**
    * 获取莱普森扶手分页列表
    *
    * @param queryParams 查询参数
    * @return {@link IPage<LpsOrderFsVO>} 莱普森扶手分页列表
    */
    @Override
    public IPage<LpsOrderFsVO> getLpsOrderFsPage(LpsOrderFsQuery queryParams) {
        Page<LpsOrderFsVO> pageVO = this.baseMapper.getLpsOrderFsPage(
                new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),
                queryParams
        );
        return pageVO;
    }
    
    /**
     * 获取莱普森扶手表单数据
     *
     * @param id 莱普森扶手ID
     * @return
     */
    @Override
    public LpsOrderFsForm getLpsOrderFsFormData(Long id) {
        LpsOrderFs entity = this.getById(id);
        return lpsOrderFsConverter.toForm(entity);
    }
    
    /**
     * 新增莱普森扶手
     *
     * @param formData 莱普森扶手表单对象
     * @return
     */
    @Override
    public boolean saveLpsOrderFs(LpsOrderFsForm formData) {
        LpsOrderFs entity = lpsOrderFsConverter.toEntity(formData);
        return this.save(entity);
    }
    
    /**
     * 更新莱普森扶手
     *
     * @param id   莱普森扶手ID
     * @param formData 莱普森扶手表单对象
     * @return
     */
    @Override
    public boolean updateLpsOrderFs(Long id,LpsOrderFsForm formData) {
        LpsOrderFs entity = lpsOrderFsConverter.toEntity(formData);
        return this.updateById(entity);
    }
    
    /**
     * 删除莱普森扶手
     *
     * @param ids 莱普森扶手ID，多个以英文逗号(,)分割
     * @return
     */
    @Override
    public boolean deleteLpsOrderFss(String ids) {
        Assert.isTrue(StrUtil.isNotBlank(ids), "删除的莱普森扶手数据为空");
        // 逻辑删除
        List<Long> idList = Arrays.stream(ids.split(","))
                .map(Long::parseLong)
                .toList();
        return this.removeByIds(idList);
    }

}
